/*
 * Created on 08/10/2009
 *
 */
package com.stefanini.pe.bbva.mbl.smanager;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;

/**
 * @author Administrador
 *
 */
public class ItemSessionCollection extends ArrayList implements Serializable
{
    // Methods
    public void Add(ItemSession oItem)
    {
        super.add(oItem);
    }

    public boolean Contains(String strKey)
    {
        return (this.Item(strKey) != null);
    }

    public int IndexOf(String strKey)
    {
        //ItemSession session = new ItemSession();
        //session.setKey(strKey);        
        //return Collections.binarySearch(this,session);
    	int index = -1;
    	for(int i=0;i<this.size();i++)
    	{
    		ItemSession ses = (ItemSession)this.get(i);
    		if (ses.getKey().equals(strKey))
    		{index = i;break;}
    	}
    	return index;
        
    }

    public ItemSession Item(String strKey)
    {
        int index = this.IndexOf(strKey);
        if (index > -1)
        {
            return (ItemSession)super.get(index);
        }
        return null;
    }

    public void Sort()
    {   
        Collections.sort(this);
    }
    public static void main(String args[])
    {
    	ItemSessionCollection oItemSessionCollection = new ItemSessionCollection();
    	ItemSession oItemSession = new ItemSession();
    	oItemSession.setKey("Key51");
    	oItemSession.setContent("Content51");
    	oItemSessionCollection.Add(oItemSession);
    	ItemSession oItemSession2 = new ItemSession();
    	oItemSession2.setKey("Key2");
    	oItemSession2.setContent("Content2");
    	oItemSessionCollection.Add(oItemSession2);
    	ItemSession oItemSession3 = new ItemSession();
    	oItemSession3.setKey("Key11");
    	oItemSession3.setContent("Content11");
    	oItemSessionCollection.Add(oItemSession3);
    	
    	oItemSessionCollection.Sort();
    	//Collections.sort(oItemSessionCollection);
    	
    	
    	for(int i = 0 ; i < oItemSessionCollection.size(); i++ )
    	{
    		System.out.println(((ItemSession)oItemSessionCollection.get(i)).getKey());
    		System.out.println(((ItemSession)oItemSessionCollection.get(i)).getContent());
    		
    	}
    	
    	
    
    }
}
